package com.contory.ssn_lgnd.app.maingame;

import com.contory.ssn_lgnd.app.Assets;
import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.app.comp.ViewObject;
import com.contory.ssn_lgnd.framework.gl.Camera2D;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;

public class Curtain implements UpdatePtr, DrawPtr{
	ViewObject viewBody;
	final Camera2D cam;
	float vignet = 0.0f;
	int dir = 1;
	static float VIGNET_LIMIT = 1.5f;
	boolean enableBool = true;
	static final byte STATE_DOING = 0;
	static final byte STATE_IDLE = 1; 
	byte state = 0;
	public Curtain(Camera2D cam){
		this.cam = cam;
		viewBody = new ViewObject();
		viewBody.setXY_WH_TR(cam.getPosition().x, cam.getPosition().y, 
				cam.getFrustumWidth(), cam.getFrustumHeight(), Assets.tex2_reg_whiteTexel);
	}
	
	public void setCloseCurtain(){
		enableBool = true;
		dir = 1;
		vignet = 0.0f;
		VIGNET_LIMIT = 1.5f;
		viewBody.x = cam.getPosition().x;
		viewBody.y = cam.getPosition().y;
	}
	
	public void setOpenCurtain(){
		enableBool = true;
		dir = -1;
		vignet = 2.5f;
		VIGNET_LIMIT = 0.0f;
		viewBody.x = cam.getPosition().x;
		viewBody.y = cam.getPosition().y;
	}
	
	@Override
	public void draw(SpriteBatcher batcher) {
		if(!enableBool)
			return;
		batcher.drawSprite(viewBody.x, viewBody.y, viewBody.w, viewBody.h, 0, 0, 0, 1, viewBody.tr);
	}
	
	@Override
	public void update(float deltaTime) {
		if(!enableBool)
			return;
		switch(state){
			case STATE_DOING:
			vignet += deltaTime * dir * 2;
			if((vignet < VIGNET_LIMIT && dir == -1) ||
					(vignet > VIGNET_LIMIT && dir == 1)){
				state = STATE_IDLE;
			}
			break;
			
			case STATE_IDLE:
				enableBool = false;
			break;
		}
	}
	
	public boolean getEnableBool(){
		return enableBool;
	}
	
	public float getVignettingValue(){
		return vignet;
	}
}
